﻿<div class="container_12">
    <div class="grid_6">
        <div class="module">
            <h2>
                <span></span>
            </h2>
            <div class="module-body">
                <fieldset>
                    <input id="txt_account" name="txt_account" type="text" class="input-medium" />&nbsp;&nbsp;<input class="submit-green" id="btn_account" name="btn_account"  type="button" value="Đo theo Account" />
                </fieldset>
                Đơn vị:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                @if (ViewBag.donvi != null)
                {
                    @Html.DropDownList("quan_huyen_id", ViewBag.donvi as SelectList, "---Chọn đơn vị---", new { style = "width: 39%" })
                }
                <br>
                Xã phường:&nbsp;
                @if (ViewBag.khuvuc == null)
                {
                    @Html.DropDownList("xa_phuong_id", Enumerable.Empty<SelectListItem>(), "---Chọn Xã phường---", new { style = "width: 39%" })
                }
                else
                {
                    @Html.DropDownList("xa_phuong_id", ViewBag.khuvuc as SelectList, "---Chọn Xã phường---", new { style = "width: 39%" })
                }
                <br>
                Tổ dân phố:&nbsp;
                @if (ViewBag.todanpho == null)
                {
                    @Html.DropDownList("todanpho_id", Enumerable.Empty<SelectListItem>(), "---Chọn Tổ dân phố---", new { style = "width: 38.5%" })
                }
                else
                {
                    @Html.DropDownList("todanpho_id", ViewBag.todanpho as SelectList, "---Chọn Tổ dân phố---", new { style = "width: 38.5%" })
                }
                <br>
                Dslam:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                @if (ViewBag.dslam == null)
                {
                    @Html.DropDownList("system_id", Enumerable.Empty<SelectListItem>(), "---Chọn Dslam---", new { style = "width: 38.5%" })
                }
                else
                {
                    @Html.DropDownList("system_id", ViewBag.dslam as SelectList, "---Chọn Dslam---", new { style = "width: 38.5%" })
                }
                <br>
                Cổng:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                @if (ViewBag.cong == null)
                {
                    @Html.DropDownList("cong", Enumerable.Empty<SelectListItem>(), "---Chọn Cổng---", new { style = "width: 38.7%" })
                }
                else
                {
                    @Html.DropDownList("cong", ViewBag.cong as SelectList, "---Chọn Cổng---", new { style = "width: 39%" })
                }&nbsp;<input class="submit-green" id="btn_cong" name="btn_cong" type="button" value="Đo theo cổng DSLAM" />
            </div>
        </div>
        <!-- module -->
        <div style="clear: both;">
        </div>
    </div>
    <!-- End .grid_6 -->
    <!-- To-do list -->
    <div class="grid_6">
        <div class="module">
            <h2>
                <span>Kết quả đo kiểm chất lượng đường dây ADSL</span>
            </h2>
            <div class="module-body">
                <text id="SNR_textbox" name="SNR_textbox"></text>
                <text id="result_txt" name="result_txt"></text>
                <div id="div_doidl" style="display:none">
                    <input class="submit-green" id="khoa" name="khoa" type="button" value="Khóa cổng" />
                    <input class="submit-green" id="mo" name="mo" type="button" value="Mở cổng" />
                    <input class="submit-green" id="resetcong" name="resetcong" type="button" value="Reset cổng" />
                    <input class="submit-green" id="resetdichvu" name="resetdichvu" type="button" value="Reset dịch vụ" />
                    <br><br>
                    <input type="checkbox" id="doidl" name="doidl" onclick="checkdl()">
                    Đổi DL:
                    <select disabled="disabled" name="dungluong" id="dungluong" style="width: 17%">
                        <option value="DSL4M">DSL4M</option>
                        <option value="DSL4M5">DSL4M5</option>
                        <option value="DSL5M">DSL5M</option>
                        <option value="DSL6M">DSL6M</option>
                        <option value="DSL7M">DSL7M</option>
                        <option value="DSL8M">DSL8M</option>
                        <option value="DSL9M">DSL9M</option>
                        <option value="DSL10M">DSL10M</option>
                        <option value="DSL11M">DSL11M</option>
                        <option value="DSL12M">DSL12M</option>
                        <option value="DSL13M">DSL13M</option>
                        <option value="DSL14M">DSL14M</option>
                        <option value="DSL15M">DSL15M</option>
                        <option value="DSL16M">DSL16M</option>
                        <option value="DSL17M">DSL17M</option>
                        <option value="DSL18M">DSL18M</option>
                        <option value="DSL20M">DSL20M</option>
                        <option value="DSL22M">DSL22M</option>
                    </select>                    
                    <input class="submit-green" id="reset_dl_btn" name="reset_dl_btn" type="button" value="Thay đổi" style="visibility:hidden" />
                    @*<img id="reset_dl_btn" name="reset_dl_btn" src="@Url.Content("~/Content/Body/Images/pencil.gif")" style="cursor:pointer;visibility:hidden" width="15" height="15" alt="edit" />*@
                    <text id="reset_dl_dslam" name="reset_dl_dslam"></text>
                </div>
            </div>
        </div>
        <!-- module -->
        <div style="clear: both;">
        </div>
    </div>
    <!-- End .grid_6 -->
    <div style="clear: both;">
    </div>
</div>
<script type="text/javascript">
    //$(document).ready(function () {
    //    document.getElementById("btn_account").focus();
    //});
    function reloadpage(data) {
        if (data.indexOf("html") > -1) {
            window.location.reload();
            return true;
        }
        else
            return false;
    }
    function checkdl() {
        if (document.getElementById("doidl").checked) {
            document.getElementById('dungluong').disabled = false;
            document.getElementById('reset_dl_btn').style.visibility = 'visible';
        }
        else {
            document.getElementById('dungluong').disabled = true;
            document.getElementById('reset_dl_btn').style.visibility = 'hidden';
        }
    }
    $("#reset_dl_btn").click(function () {
        $("#reset_dl_dslam").html("Vui lòng chờ...");
        $.ajax({
            type: "POST",
            url: '@Url.Action("ResetDungLuongJSon", "DslamPort")',
            data: { id: document.getElementById("id").value, dslam_type_id: document.getElementById("dslam_type_id").value, dungluong: document.getElementById("dungluong").value, ip: document.getElementById("ip").value, slot: document.getElementById("slot").value, port: document.getElementById("port").value },
            success: function (data) {
                if (reloadpage(data)) return;
                if (data.indexOf("DSLAM") > -1) {
                    $("#reset_dl_dslam").html(data);
                }
                else {
                    $("#reset_dl_dslam").html("Đổi dung lượng cổng DSLAM thành công!");
                }
            }
        })
    });
    $("#resetcong").click(function () {
        $("#result_txt").html("Vui lòng chờ...");
        $.ajax({
            type: "POST",
            url: '@Url.Action("ResetCongJSon", "DslamPort")',
            data: { id: document.getElementById("id").value, dslam_type_id: document.getElementById("dslam_type_id").value,  ip: document.getElementById("ip").value, slot: document.getElementById("slot").value, port: document.getElementById("port").value },
            success: function (data) {
                if (reloadpage(data)) return;
                $("#result_txt").html(data);
            }
        })
    });
    $("#btn_account").click(function () {
        if (document.getElementById("txt_account").value.length < 4) {
            alert('Account phải có nhiều hơn 3 ký tự');
            return;
        }
        document.getElementById('div_doidl').style.display = 'none';
        document.getElementById("doidl").checked = false;
        $("#reset_dl_dslam").html("");
        $("#result_txt").html("");
        document.getElementById('dungluong').disabled = true;
        $("#SNR_textbox").html("Vui lòng chờ...");
        $.ajax({
            type: "POST",
            url: '@Url.Action("GetSNRJSon", "DslamPort")',
            data: { account: document.getElementById("txt_account").value, cong: '', system_id: '' },
            success: function (data) {

                if (reloadpage(data)) return;
                $("#SNR_textbox").html(data);
                document.getElementById('div_doidl').style.display = 'block';
            }
        })

    });
    $("#btn_cong").click(function () {
        if (document.getElementById("cong").value == "") {
            alert("Phải chọn cổng");
            return;
        }
        document.getElementById('div_doidl').style.display = 'none';
        document.getElementById("doidl").checked = false;
        $("#reset_dl_dslam").html("");
        $("#result_txt").html("");
        document.getElementById('dungluong').disabled = true;
        $("#SNR_textbox").html("Vui lòng chờ...");
        $.ajax({
            type: "POST",
            url: '@Url.Action("GetSNRJSon", "DslamPort")',
            data: { account: '', cong: document.getElementById("cong").value, system_id: document.getElementById("system_id").value },
            success: function (data) {
                if (reloadpage(data)) return;
                $("#SNR_textbox").html(data);
                document.getElementById('div_doidl').style.display = 'block';
            }
        })
    });
    $("#quan_huyen_id").change(function () {
        $("#todanpho_id").html("<option value=''>---Chọn Tổ dân phố---</option>");
        $("#cong").html("<option value=''>---Chọn cổng---</option>")
        $.ajax({
            type: "POST",
            async: false,
            url: '@Url.Action("getDslamJson", "DslamPort")',
            data: { quan_huyen_id: $("#quan_huyen_id > option:selected").attr("value"), Order: "name" },
            success: function (data) {
                if (data.indexOf("html") > -1)
                    window.location.reload();
                var items = [];
                items.push("<option value=''>---Chọn Dslam---</option>");
                $.each(data, function () {
                    items.push("<option value='" + this.Value + "'>" + this.Text + "</option>");
                });
                $("#system_id").html(items.join(' '));
            }
        })
    });
    $("#quan_huyen_id").change(function () {
        $.ajax({
            type: "POST",
            url: '@Url.Action("getKhuvucJson", "DslamPort")',
            data: { quan_huyen_id: $("#quan_huyen_id > option:selected").attr("value"), Order: "ten" },
            success: function (data) {
                if (data.indexOf("html") > -1)
                    window.location.reload();
                var items = [];
                items.push("<option value=''>---Chọn Xã phường---</option>");
                $.each(data, function () {
                    items.push("<option value='" + this.Value + "'>" + this.Text + "</option>");
                });
                $("#xa_phuong_id").html(items.join(' '));
            }
        })
    });
    $("#xa_phuong_id").change(function () {
        $("#system_id").html("<option value=''>---Chọn Dslam---</option>");
        $("#cong").html("<option value=''>---Chọn cổng---</option>")
        $.ajax({
            type: "POST",
            url: '@Url.Action("getTodanphoJson", "DslamPort")',
            data: { xa_phuong_id: $("#xa_phuong_id > option:selected").attr("value"), Order: "ten" },
            success: function (data) {
                if (data.indexOf("html") > -1)
                    window.location.reload();
                var items = [];
                items.push("<option value=''>---Chọn Tổ dân phố---</option>");
                $.each(data, function () {
                    items.push("<option value='" + this.Value + "'>" + this.Text + "</option>");
                });
                $("#todanpho_id").html(items.join(' '));
            }
        })
    });
    $("#xa_phuong_id").change(function () {
        $.ajax({
            type: "POST",
            url: '@Url.Action("getDslamByKhuvucJson", "DslamPort")',
            data: { xa_phuong_id: $("#xa_phuong_id > option:selected").attr("value"), Order: "name" },
            success: function (data) {
                if (data.indexOf("html") > -1)
                    window.location.reload();
                var items = [];
                items.push("<option value=''>---Chọn Dslam---</option>");
                $.each(data, function () {
                    items.push("<option value='" + this.Value + "'>" + this.Text + "</option>");
                });
                $("#system_id").html(items.join(' '));
            }
        })
    });
    $("#todanpho_id").change(function () {
        $("#cong").html("<option value=''>---Chọn cổng---</option>")
        $.ajax({
            type: "POST",
            url: '@Url.Action("getDslamByTodanphoJson", "DslamPort")',
            data: { todanpho_id: $("#todanpho_id > option:selected").attr("value"), Order: "name" },
            success: function (data) {
                if (data.indexOf("html") > -1)
                    window.location.reload();
                var items = [];
                items.push("<option value=''>---Chọn Dslam---</option>");
                $.each(data, function () {
                    items.push("<option value='" + this.Value + "'>" + this.Text + "</option>");
                });
                $("#system_id").html(items.join(' '));
            }
        })
    });
    $("#system_id").change(function () {
        $.ajax({
            type: "POST",
            url: '@Url.Action("getcongJson", "DslamPort")',
            data: { system_id: $("#system_id > option:selected").attr("value"), Order: "cong" },
            success: function (data) {
                if (data.indexOf("html") > -1)
                    window.location.reload();
                var items = [];
                items.push("<option value=''>---Chọn cổng---</option>");
                $.each(data, function () {
                    items.push("<option value='" + this.Value + "'>" + this.Text + "</option>");
                });
                $("#cong").html(items.join(' '));
            }
        })
    });

    /////////////////
    $("#khoa").click(function () {
        var trang_thai = 0;
        $("#result_txt").html("Vui lòng chờ...");
        $.ajax({
            type: "POST",
            url: '@Url.Action("Lock_Unlock_PortJSon", "DslamPort")',
            data: { cong: document.getElementById("cong_value").value, system_id: document.getElementById("system_id_value").value, status: trang_thai },
            success: function (data) {
                if (reloadpage(data)) return;
                $("#result_txt").html(data);
            }
        })
    });
    $("#mo").click(function () {
        var trang_thai = 1;
        $("#result_txt").html("Vui lòng chờ...");
        $.ajax({
            type: "POST",
            url: '@Url.Action("Lock_Unlock_PortJSon", "DslamPort")',
            data: { cong: document.getElementById("cong_value").value, system_id: document.getElementById("system_id_value").value, status: trang_thai },
            success: function (data) {
                if (reloadpage(data)) return;
                $("#result_txt").html(data);
            }
        })
    });

    $("#resetdichvu").click(function () {
        var x;
        x = "16";         
        $("#result_txt").html("Vui lòng chờ (Chỉ reset dịch vụ MYTV)...");
        $.ajax({
            type: "POST",
            url: '@Url.Action("Reset_Account_In_PortJSon", "DslamPort")',
            data: { account: '', cong: document.getElementById("cong_value").value, system_id: document.getElementById("system_id_value").value, option: x },
            success: function (data) {
                if (reloadpage(data)) return;
                $("#result_txt").html(data);
            }
        })
        
    });
</script>
